package com.unohacha.qqj.fzdr.personal.view.activity;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.common.bean.HttpResult;
import com.unohacha.qqj.fzdr.common.bean.ZhanhuiDetail;
import com.unohacha.qqj.fzdr.common.http.RetrofitManager;
import com.unohacha.qqj.mylibrary.base.BaseActivity;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class ZhanhuiDetailActivity extends BaseActivity {
    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.tv_site)
    TextView tvSite;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_area)
    TextView tvArea;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_range)
    TextView tvRange;
    @BindView(R.id.tv_introduce)
    TextView tvIntroduce;
    private String id;
    @BindView(R.id.tv_phone)
    TextView tvPhone;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_zhanhui_detail;
    }

    @Override
    protected void initView() {
        commonTitle.setText("展会信息");
        commonRightImage.setVisibility(View.INVISIBLE);
        id = this.getIntent().getExtras().getString("id");
        System.out.println(id);
        if (null != id) {
            gtMessage();
        }
    }

    private void gtMessage() {
        showLoading();
        RetrofitManager.getInstance()
                .ZhanhuiDetail(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .throttleFirst(2, TimeUnit.SECONDS)
                .subscribe(new Action1<HttpResult<ZhanhuiDetail>>() {
                    @Override
                    public void call(HttpResult<ZhanhuiDetail> zhanhuiDetailHttpResult) {
                        if (zhanhuiDetailHttpResult.getCode() == 1) {
                            RefreshUi(zhanhuiDetailHttpResult.getData());
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        hideLoading();
                    }
                });
    }

    private void RefreshUi(ZhanhuiDetail date) {
        Log.d("addressName",date.getArea_id()+" "+date.getCity_id());
        tvTitle.setText(date.getTitle());
        tvSite.setText(date.getCity_name() + " "+date.getFabuqu_name() +" "+ date.getAddress_content());
        tvTime.setText(date.getExhibition_time());
        tvArea.setText(date.getProportion() + "㎡");
        tvNumber.setText(date.getQuantity());
        tvRange.setText(date.getScope());
        tvIntroduce.setText(date.getContent());
        tvPhone.setText(date.getTel());
        Glide.with(this)
                .load(date.getThumb().get(0).getThumb())
                .into(image);
        hideLoading();
    }

    @OnClick(R.id.common_back)
    public void onViewClicked() {
        finish();
    }
}
